package com.bread.tliaswebmanagement.service.impl;

import com.bread.tliaswebmanagement.mapper.ClazzMapper;
import com.bread.tliaswebmanagement.mapper.EmpMapper;
import com.bread.tliaswebmanagement.mapper.StudentMapper;
import com.bread.tliaswebmanagement.pojo.ClazzCountStatistic;
import com.bread.tliaswebmanagement.pojo.JobStatistc;
import com.bread.tliaswebmanagement.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public JobStatistc getEmpJobStatistic() {
        List<Map<String, Object>> empJobStatistic = empMapper.getEmpJobStatistic();
        //实际上每一行数据对应一个map集合，map集合里有多个key-value键值对，key是column名，value是column值
        List<Object> jobList = empJobStatistic.stream().map(dataMap -> dataMap.get("position")).toList();
        List<Object> dataList = empJobStatistic.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobStatistc(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderStatistic() {
        return empMapper.getEmpGenderStatistic();
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeStatistic() {
        return studentMapper.getStudentDegreeStatistic();
    }

    @Override
    public ClazzCountStatistic getClazzCountStatistic() {
        List<Map<String, Object>> clazzCountStatistic = clazzMapper.getClazzCountStatistic();
        List<Object> clazzList = clazzCountStatistic.stream().map(dataMap -> dataMap.get("name")).toList();
        List<Object> dataList = clazzCountStatistic.stream().map(dataMap -> dataMap.get("num")).toList();
        return new ClazzCountStatistic(clazzList, dataList);
    }
}
